package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(("/admin/category"))
@Slf4j
public class CategoryController {
    @Autowired
    protected CategoryService categoryService;
    @GetMapping("/page")
    public Result<PageResult> queryPage(CategoryPageQueryDTO pageInfo){
        PageResult res = categoryService.pageQuery(pageInfo);
        return Result.success(res);
    }
    @PostMapping
    public Result addCategoryType(@RequestBody CategoryDTO dto){
        categoryService.addCategoryType(dto);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result disbaleStatus(@PathVariable Integer status,Long id){
        categoryService.disbale(status, id);
        return Result.success("禁用成功～");
    }
    @PutMapping
    public Result updateName(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateName(categoryDTO);
        return Result.success("修改成功");
    }

    @DeleteMapping
    public Result deleteCategoryById(Long id){
        categoryService.deleteById(id);
        return Result.success("删除成功～");
    }

    @GetMapping("/list")
    public Result<List> queryList(Integer type){
         List<Category> page = categoryService.queryList(type);
        return Result.success(page);
    }
}
